package com.njbdqn.myfilm.componses;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class PageBean<T> {
	@Autowired
	private IPageDAO<T> pdao;
	@Autowired
	private PageParam pip;
	
	private int countPage;
	private List<T> data = new ArrayList<T>();
	private int prev;
	private int next;
	
	public PageBean<T> openBean(){
		countPage = pdao.getCountPage(pip);
		data = pdao.findCurrentPageData(pip);
		prev = pip.getCurrentPage()-1<=1?1:pip.getCurrentPage()-1;
		next = pip.getCurrentPage()+1>=countPage?countPage:pip.getCurrentPage()+1;
		return this;
	}

	public PageParam getPip() {
		return pip;
	}

	public void setPip(PageParam pip) {
		this.pip = pip;
	}

	public int getCountPage() {
		return countPage;
	}

	public void setCountPage(int countPage) {
		this.countPage = countPage;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public int getPrev() {
		return prev;
	}

	public void setPrev(int prev) {
		this.prev = prev;
	}

	public int getNext() {
		return next;
	}

	public void setNext(int next) {
		this.next = next;
	}
	
}
